package com.psa.element;

import android.content.ContentValues;
import android.database.Cursor;
import com.psa.tool.DBTool;

/**
 * @author david
 */
public class CustomerShowcase implements ISqlObject, IJson {
    public int pk_id = 0;
    public String CustomerID = "";
    public int ShowcaseID = 0;
    public String qyDate = "";
    public String jsDate = "";
    public Showcase showcase = null;

    @Override
    public String toJson() {
        return null;
    }

    @Override
    public int insert(DBTool dbTool) {
        if (pk_id > 0) {
            return update(dbTool);
        }
        ContentValues values = new ContentValues();
        values.put("CustomerID", CustomerID.trim());
        values.put("ShowcaseID", ShowcaseID);
        values.put("qyDate", qyDate);
        values.put("jsDate", jsDate);
        pk_id = (int)dbTool.insert("CustomerShowcase", values);
        return pk_id;
    }

    @Override
    public int update(DBTool dbTool) {
        ContentValues values = new ContentValues();
        values.put("pk_id", pk_id);
        values.put("qyDate", qyDate);
        values.put("jsDate", jsDate);
        String where = "pk_id = ?";
        String[] value = { String.valueOf(pk_id) };
        int i = dbTool.update("CustomerShowcase", values, where, value);
        return i;
    }

    @Override
    public int delete(DBTool dbTool) {
        String where = "pk_id = ?";
        String[] value = { String.valueOf(pk_id) };
        return dbTool.delete("CustomerShowcase", where, value);
    }

    @Override
    public ISqlObject full(Cursor cursor) {
        if (cursor!=null && cursor.moveToNext()) {
            CustomerShowcase customerShowcase = new CustomerShowcase();
            customerShowcase.pk_id = cursor.getInt(0);
            customerShowcase.CustomerID = cursor.getString(1);
            customerShowcase.ShowcaseID = cursor.getInt(2);
            customerShowcase.qyDate = cursor.getString(3);
            customerShowcase.jsDate = cursor.getString(4);
            customerShowcase.showcase = Showcase.getShowcase(customerShowcase.ShowcaseID);
            return customerShowcase;
        }
        return null;
    }

    @Override
    public void clear(DBTool dbTool) {
        dbTool.delete("CustomerShowcase", "pk_id Like ?", new String[]{"%"});
    }

    @Override
    public String getDataSql() {
        return "CustomerShowcase";
    }

    @Override
    public String getSyncMethod() {
        return "getdataobjects";
    }
}
